import wx
import sys

# reload(sys)
# sys.setdefaultencoding('utf-8')

ID_FIND = 301
ID_FIND_NEXT = 302
ID_REPLACE = 303

class SearchDialog(wx.Dialog):
    def __init__(self, parent, id):
        self.app = wx.GetApp()
        wx.Dialog.__init__(self, parent, id, "查找", size=(400, 175))
        self.InitUI()

    def InitUI(self):
        self.panel = wx.Panel(self)
        # 显示查找内容的静态文本
        wx.StaticText(self.panel, -1, "查找内容：", pos = (5, 20))
        # 输入查找内容的可编辑文本
        self.text_find = wx.TextCtrl(self.panel, -1, "", pos = (80, 20), size = (300, 25))
        self.text_find.Bind(wx.EVT_TEXT, self.OnText)
        # 放置一个按钮实现“查找下一个功能”
        self.find_next_btn = wx.Button(self.panel, ID_FIND_NEXT, "查找下一个", pos = (5, 50), size = (100, 25))
        self.find_next_btn.Disable()
        # 放置一个复选框用于实现“区分大小写”功能
        self.check_case = wx.CheckBox(self.panel, -1, "区分大小写", pos = (5, 80))
        self.check_case.Bind(wx.EVT_CHECKBOX, self.OnCaseSensitive)
        # 放置一个单选框用于实现“方向”功能
        list_direction = ["向下", "向上"]
        self.radio_direction = wx.RadioBox(self.panel, -1, "方向", pos = (5, 110), choices = list_direction, majorDimension = 2, style = wx.RA_SPECIFY_COLS)
        self.radio_direction.Bind(wx.EVT_RADIOBOX, self.OnDirection)
        # 关闭该对话框
        self.close_btn = wx.Button(self.panel, wx.ID_CLOSE, "关闭", pos = (300, 50), size = (100, 25))
        self.close_btn.Bind(wx.EVT_BUTTON, self.OnClose)
        pass

    # 文本行为侦测
    def OnText(self, event):
        print("ongoing")
        self.text_find.Enable()
        print("Come on...")

    #  区分大小写
    def OnCaseSensitive(self, event):
        print("case sensitive")

    # 方向控制
    def OnDirection(self, event):
        print(f"direction：{self.radio_direction.GetStringSelection()}, {self.radio_direction.GetSelection()}")

    # 关闭该对话框
    def OnClose(self, event):
        self.Destroy()
